/**
 * 大小玩法下注类型统一枚举
 * 用于统一管理前端和后端的下注类型映射
 */

// 基础下注类型枚举
export enum BetType {
  BIG = 1, // 大
  SMALL = 2, // 小
  ODD = 3, // 单
  EVEN = 4, // 双
  TRIPLE = 5, // 豹子
  SHANG_QIAN = 6, // 上签 (新增)
}

// 货币类型枚举
export enum CurrencyType {
  GOLD = 1, // 金币
  SILVER = 2, // 银币
}

// 前端下注类型映射枚举 (1-12)
export enum FrontendBetType {
  // 小
  SMALL_GOLD = 1, // 小金子
  SMALL_SILVER = 2, // 小银子

  // 大
  BIG_GOLD = 3, // 大金子
  BIG_SILVER = 4, // 大银子

  // 豹子
  TRIPLE_GOLD = 5, // 豹子金子
  TRIPLE_SILVER = 6, // 豹子银子

  // 单
  ODD_GOLD = 7, // 单金子
  ODD_SILVER = 8, // 单银子

  // 双
  EVEN_GOLD = 9, // 双金子
  EVEN_SILVER = 10, // 双银子

  // 上签
  SHANG_QIAN_GOLD = 11, // 上签金子
  SHANG_QIAN_SILVER = 12, // 上签银子
}

// 下注类型中文名称映射
export const BET_TYPE_NAMES = {
  [BetType.BIG]: "太",
  [BetType.SMALL]: "少",
  [BetType.ODD]: "阴",
  [BetType.EVEN]: "阳",
  [BetType.TRIPLE]: "上上签",
  [BetType.SHANG_QIAN]: "上签",
} as const;

// 下注类型完整中文名称映射
export const BET_TYPE_FULL_NAMES = {
  [BetType.BIG]: "太",
  [BetType.SMALL]: "少",
  [BetType.ODD]: "阴",
  [BetType.EVEN]: "阳",
  [BetType.TRIPLE]: "上上签",
  [BetType.SHANG_QIAN]: "上签",
} as const;

// 货币类型中文名称映射
export const CURRENCY_TYPE_NAMES = {
  [CurrencyType.GOLD]: "金",
  [CurrencyType.SILVER]: "银",
} as const;

// 前端下注类型到后端下注类型的映射
export const FRONTEND_TO_BET_TYPE_MAP = {
  [FrontendBetType.SMALL_GOLD]: BetType.SMALL,
  [FrontendBetType.SMALL_SILVER]: BetType.SMALL,
  [FrontendBetType.BIG_GOLD]: BetType.BIG,
  [FrontendBetType.BIG_SILVER]: BetType.BIG,
  [FrontendBetType.TRIPLE_GOLD]: BetType.TRIPLE,
  [FrontendBetType.TRIPLE_SILVER]: BetType.TRIPLE,
  [FrontendBetType.ODD_GOLD]: BetType.ODD,
  [FrontendBetType.ODD_SILVER]: BetType.ODD,
  [FrontendBetType.EVEN_GOLD]: BetType.EVEN,
  [FrontendBetType.EVEN_SILVER]: BetType.EVEN,
  [FrontendBetType.SHANG_QIAN_GOLD]: BetType.SHANG_QIAN,
  [FrontendBetType.SHANG_QIAN_SILVER]: BetType.SHANG_QIAN,
} as const;

// 前端下注类型到货币类型的映射
export const FRONTEND_TO_CURRENCY_TYPE_MAP = {
  [FrontendBetType.SMALL_GOLD]: CurrencyType.GOLD,
  [FrontendBetType.SMALL_SILVER]: CurrencyType.SILVER,
  [FrontendBetType.BIG_GOLD]: CurrencyType.GOLD,
  [FrontendBetType.BIG_SILVER]: CurrencyType.SILVER,
  [FrontendBetType.TRIPLE_GOLD]: CurrencyType.GOLD,
  [FrontendBetType.TRIPLE_SILVER]: CurrencyType.SILVER,
  [FrontendBetType.ODD_GOLD]: CurrencyType.GOLD,
  [FrontendBetType.ODD_SILVER]: CurrencyType.SILVER,
  [FrontendBetType.EVEN_GOLD]: CurrencyType.GOLD,
  [FrontendBetType.EVEN_SILVER]: CurrencyType.SILVER,
  [FrontendBetType.SHANG_QIAN_GOLD]: CurrencyType.GOLD,
  [FrontendBetType.SHANG_QIAN_SILVER]: CurrencyType.SILVER,
} as const;

// 后端下注类型到前端下注类型的映射 (用于生成前端显示)
export const BET_TYPE_TO_FRONTEND_MAP = {
  [BetType.SMALL]: {
    [CurrencyType.GOLD]: FrontendBetType.SMALL_GOLD,
    [CurrencyType.SILVER]: FrontendBetType.SMALL_SILVER,
  },
  [BetType.BIG]: {
    [CurrencyType.GOLD]: FrontendBetType.BIG_GOLD,
    [CurrencyType.SILVER]: FrontendBetType.BIG_SILVER,
  },
  [BetType.TRIPLE]: {
    [CurrencyType.GOLD]: FrontendBetType.TRIPLE_GOLD,
    [CurrencyType.SILVER]: FrontendBetType.TRIPLE_SILVER,
  },
  [BetType.ODD]: {
    [CurrencyType.GOLD]: FrontendBetType.ODD_GOLD,
    [CurrencyType.SILVER]: FrontendBetType.ODD_SILVER,
  },
  [BetType.EVEN]: {
    [CurrencyType.GOLD]: FrontendBetType.EVEN_GOLD,
    [CurrencyType.SILVER]: FrontendBetType.EVEN_SILVER,
  },
  [BetType.SHANG_QIAN]: {
    [CurrencyType.GOLD]: FrontendBetType.SHANG_QIAN_GOLD,
    [CurrencyType.SILVER]: FrontendBetType.SHANG_QIAN_SILVER,
  },
} as const;

/**
 * 根据前端下注类型获取后端下注类型和货币类型
 */
export function parseFrontendBetType(frontendType: string): {
  betType: BetType;
  currencyType: CurrencyType;
} {
  const typeNum = parseInt(frontendType);
  const betType = FRONTEND_TO_BET_TYPE_MAP[typeNum as FrontendBetType];
  const currencyType =
    FRONTEND_TO_CURRENCY_TYPE_MAP[typeNum as FrontendBetType];

  if (!betType || !currencyType) {
    throw new Error(`无效的下注类型: ${frontendType}`);
  }

  return { betType, currencyType };
}

/**
 * 根据后端下注类型和货币类型获取前端下注类型
 */
export function getFrontendBetType(
  betType: BetType,
  currencyType: CurrencyType
): FrontendBetType {
  const frontendType = BET_TYPE_TO_FRONTEND_MAP[betType]?.[currencyType];
  if (!frontendType) {
    throw new Error(`无效的下注类型组合: ${betType}, ${currencyType}`);
  }
  return frontendType;
}

/**
 * 获取下注类型的中文名称
 */
export function getBetTypeName(betType: BetType): string {
  return BET_TYPE_NAMES[betType] || "未知";
}

/**
 * 获取下注类型的完整中文名称
 */
export function getBetTypeFullName(betType: BetType): string {
  return BET_TYPE_FULL_NAMES[betType] || "未知";
}

/**
 * 获取货币类型的中文名称
 */
export function getCurrencyTypeName(currencyType: CurrencyType): string {
  return CURRENCY_TYPE_NAMES[currencyType] || "未知";
}

/**
 * 获取下注类型的完整描述 (包含货币类型)
 */
export function getBetTypeDescription(
  betType: BetType,
  currencyType: CurrencyType
): string {
  const betName = getBetTypeName(betType);
  const currencyName = getCurrencyTypeName(currencyType);
  return `${betName}${currencyName}`;
}

/**
 * 获取下注类型的完整描述 (包含货币类型，用于显示)
 */
export function getBetTypeFullDescription(
  betType: BetType,
  currencyType: CurrencyType
): string {
  const betName = getBetTypeFullName(betType);
  const currencyName = getCurrencyTypeName(currencyType);
  return `${betName}${currencyName}`;
}
